import 'package:flutter/material.dart';
import 'package:flutterprovider/page/login/login.dart';
import 'package:flutterprovider/provider_set.dart';
import 'package:flutterprovider/ui/ChangeUserInfo.dart';
import 'package:provider/provider.dart';

import 'providers/count.dart';
import 'providers/themedata.dart';

void main() => runApp(MultiProvider(
      providers: providers,
      child: MyApp(),
    ));

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
//        theme: ThemeData(
//          primarySwatch: Colors.blue,
//        ),
      theme: Provider.of<ThemeDataModel>(context, listen: true).themeData,
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text("加的值是:${Provider.of<Count>(context).count}"),
            MaterialButton(
              color: Colors.red,
              textColor: Colors.white,
              child: Text("加法"),
              onPressed: () {
                print("111");
                Provider.of<Count>(context, listen: false).add();
              },
            ),
            TextField(
              decoration: InputDecoration(
                border: OutlineInputBorder(
                  gapPadding: 10.0,
                  borderRadius: BorderRadius.circular(10.0),
                ),
                labelText: "请输入内容",
                helperText: "123",
                prefixIcon: Icon(Icons.people),
              ),
              onChanged: (v) {
                print("onchange==>" + v);
              },
              onSubmitted: (v) {
                print("onSubmitted==>" + v);
              },
            ),
            FlatButton(
              color: Colors.lightBlueAccent,
              textColor: Colors.white,
              child: Text("切换主题颜色"),
              onPressed: () {
                Provider.of<ThemeDataModel>(context, listen: false).change();
              },
            ),
            Login(),
            FlatButton(
              color: Colors.yellow,
              textColor: Colors.white,
              child: Text("下一个页面"),
              onPressed: () {
                Navigator.push(context,
                    MaterialPageRoute(builder: (_) => ChangeUserInfoPage()));
              },
            ),
          ],
        ),
      ),
    );
  }
}
